package thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author DBX
 * @effect
 * @date 2021/09/10/20:30
 */
public class CallableThread {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask task = new FutureTask(new Callable() {
            @Override
            public Object call() throws Exception {
                System.out.println("begin");
                Thread.sleep(10000);
                System.out.println("end");
                int a = 1,b=2;
                return a+b;
            }
        });
        Thread t = new Thread(task);
        t.start();
        Object o = task.get();
        System.out.println(o);

    }
}
